package org.example.test_qlexpress.function;

import com.ql.util.express.Operator;

import java.math.BigDecimal;
import java.math.BigInteger;

public class PowFunction extends Operator {
    public Object executeInner(Object[] objects) throws Exception {
        if (objects == null || objects.length == 0) {
            throw new RuntimeException("没有传入任何参数。");
        }
        if (objects.length < 2) {
            throw new RuntimeException("传入的参数不能少于2个。");
        }
        Object a = objects[0];
        Object b = objects[1];
        if (a == null || b == null) {
            throw new RuntimeException("参数不能为null。");
        }
        Double _a;
        Double _b;
        if (a instanceof Number && b instanceof Number) {
            _a = ((Number) a).doubleValue();
            _b = ((Number) b).doubleValue();
            return Math.pow(_a, _b);
        }
        throw new RuntimeException("不支持该数据类型：" + a + "，" + b);
    }
}
